package org.shoukaiseki.kakaroto;

import org.shoukaiseki.common.utils.ListUtils;

import java.util.List;

/**
 *
 **/
public class FilterParserJpaOption {

    //后缀关键字,按顺序
    private String[] keyword;

    //描述
    private String description;

    //备注
    private String remark;

    private String sample;


//https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference

    public static List<FilterParserJpaOption> japOptionList(){
        List<FilterParserJpaOption> jpaOptions = ListUtils.newArrayList(
                new FilterParserJpaOption().setKeyword("Customize")
                        .setDescription("自定义,将会忽略"),
                new FilterParserJpaOption().setKeyword("IsNotNull", "NotNull").setRemark("过滤值要传'1'才启用过滤"),
                new FilterParserJpaOption().setKeyword("IsNull", "Null").setRemark("过滤值要传'1'才启用过滤"),
                new FilterParserJpaOption().setKeyword("NotEmpty","IsNotEmpty").setDescription("如果不为空字符").setRemark("过滤值要传'1'才启用过滤"),
                new FilterParserJpaOption().setKeyword("IsEmpty","Empty").setDescription("如果为空字符").setRemark("过滤值要传'1'才启用过滤"),
                new FilterParserJpaOption().setKeyword("FindInSet").setDescription("and FIND_IN_SET(#{sksParams.userIdFindInSet},t1.userId)"),
                new FilterParserJpaOption().setKeyword("NotLike"),
                new FilterParserJpaOption().setKeyword("Like"),
                new FilterParserJpaOption().setKeyword("Equals","Is"),
                new FilterParserJpaOption().setKeyword("Between"),
                new FilterParserJpaOption().setKeyword("StrRange").setDescription("字符串范围,json数组,2个元素,会格式化成 [第1个元素]>= and [第2个元素]<="),
                new FilterParserJpaOption().setKeyword("LessThan","Before"),
                new FilterParserJpaOption().setKeyword("LessThanEqual"),
                new FilterParserJpaOption().setKeyword("LessThanEqualYMDDate").setDescription("日期小于等于该时间")
                        .setRemark("例如: xxxLessThanEqualYMDDate=2022-01-01 ,执行的语句 t1.create_time <= concat(#{xxxLessThanEqualYMDDate},' 23:59:59')"),
                new FilterParserJpaOption().setKeyword("GreaterZero").setDescription("如果大于0").setRemark("过滤值传'1'才启用过滤"),
                new FilterParserJpaOption().setKeyword("GreaterThan","After").setDescription(""),
                new FilterParserJpaOption().setKeyword("GreaterThanEqual"),
                new FilterParserJpaOption().setKeyword("GreaterThanEqualYMDDate").setDescription("日期小于等于该时间")
                        .setRemark("例如: xxxGreaterThanEqualYMDDate=2022-01-01 ,执行的语句 t1.create_time >= concat(#{xxxGreaterThanEqualYMDDate},' 23:59:59')"),
                new FilterParserJpaOption().setKeyword("StartingWith"),
                new FilterParserJpaOption().setKeyword("EndingWith"),
                new FilterParserJpaOption().setKeyword("Containing"),
                new FilterParserJpaOption().setKeyword("NotIn"),
                new FilterParserJpaOption().setKeyword("Not"),
                new FilterParserJpaOption().setKeyword("In"),
                new FilterParserJpaOption().setKeyword("AndTrue")
                        .setDescription("位过滤,只显示对应位为1")
                        .setSample("and (bit_type & #{bitTypeAndTrue})=#{bitTypeAndTrue}"),
                new FilterParserJpaOption().setKeyword("AndFalse")
                        .setDescription("位过滤,只显示对应位为0的数据")
                        .setSample("and !(bit_type & #{bitTypeAndFalse})"),
                new FilterParserJpaOption().setKeyword("True"),
                new FilterParserJpaOption().setKeyword("False"),
                new FilterParserJpaOption().setKeyword("IgnoreCase")
                        .setSample("and UPPER(x.name) = UPPER(#{name})")
                        .setDescription("mysql 对大小写默认不敏感的,该功能基本无用,如需区分,需要查询前加 binary 关键字,如:  and binary x.name=#{name}")
                ,

                null
        );

        return (List<FilterParserJpaOption>) jpaOptions.stream().filter((item)->item!=null);
    }


    public String[] getKeyword() {
        return keyword;
    }

    public FilterParserJpaOption setKeyword(String... keyword) {
        this.keyword = keyword;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public FilterParserJpaOption setDescription(String description) {
        this.description = description;
        return this;
    }

    public String getSample() {
        return sample;
    }

    public FilterParserJpaOption setSample(String sample) {
        this.sample = sample;
        return this;
    }

    public String getRemark() {
        return remark;
    }

    public FilterParserJpaOption setRemark(String remark) {
        this.remark = remark;
        return this;
    }
}
